<?php
namespace structure\components;

class Operation extends \components\Component
{
	public function Start()
	{
		$component = $this->GetComponent();
		$operation = $component->GetAttribute('name');

		//Get result of an operation as an array
		$sxe = core("File")->LoadXml(_COMPONENTS_DIR."operations/$operation.operation.xml");
		$xml = core("Html")->CreateElement($sxe);

		$content = component($xml, "operation"); //result array/...

		//For each array item parse the component
		//$this->ResetChildren();

		$children = $component->GetChildren();

		$res = array();

		foreach ($content as $key=>$item)
		{
			if (is_array($item))
			{
				foreach ($item as $name=>$value)
				{
					core("Registry")->Set($name, $value, $operation);
				}
			}
			else
			{
				core("Registry")->Set($key, $item, $operation);
			}

			foreach ($children as $child)
			{
				$childRes = component($child);
				$res[] = $childRes;
			}
		}

		$res = implode("\n", $res);

		return $res;
	}
}